from rest_framework.viewsets import ModelViewSet
from rest_framework.response import Response

from meiduo_admin.serializers.channels_serializer import GoodsChannelSerializer, GoodsCategorySerializer, \
    GoodsChannelGroupSerializer
from meiduo_admin.utils import PageNum
from goods.models import GoodsChannel, GoodsCategory, GoodsChannelGroup


class ChannelViewSet(ModelViewSet):
    """
        GoodsChannel表的增删改查
    """
    serializer_class = GoodsChannelSerializer
    queryset = GoodsChannel.objects.all().order_by('id')
    pagination_class = PageNum


    def categories(self, request):

        data = GoodsCategory.objects.all().order_by('id')
        ser = GoodsCategorySerializer(data, many=True)
        return Response(ser.data)

    def channel_type(self, request):

        data = GoodsChannelGroup.objects.all().order_by('id')
        ser = GoodsChannelGroupSerializer(data, many=True)
        return Response(ser.data)